import 'dart:convert';

import 'package:xws/models/user/user_basic_info.dart';

/// 反馈对象
class FeedbackObj {
  FeedbackObj({
    this.avatarUrl,
    this.content,
    this.createdAt,
    this.id,
    this.nickName,
    this.title,
    this.userId,
  }) {
    imageUrlList = <String>[];
  }

  String? avatarUrl;
  String? content;
  String? createdAt;
  String? id;
  late List<String> imageUrlList;
  String? nickName;
  String? title;
  String? userId;

  /// 从用户信息补充参数
  void fromUser(UserBasicInfo info) {
    avatarUrl = info.avatarUrl;
    nickName = info.nickName;
    userId = info.id;
  }

  /// 检测参数
  String check() {
    if (title == null || title!.isEmpty) return '请输入标题';
    if (content == null || content!.isEmpty) return '请完善描述';

    return 'success';
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        if (avatarUrl != null && avatarUrl!.isNotEmpty) 'avatarUrl': avatarUrl,
        if (content != null) 'content': content,
        if (id != null) 'id': id,
        if (imageUrlList.isNotEmpty) 'imageUrlList': json.encode(imageUrlList.toString()),
        if (nickName != null) 'nickName': nickName,
        if (title != null) 'title': title,
        if (userId != null) 'userId': userId,
      };
}
